<?php
namespace app\store\controller;
use \Workerman\Worker;
use \Workerman\Lib\Timer;
use app\common\library\WsgtLog;
use think\Db;
class Timers{

}
$task = new Worker();
$task->onWorkerStart = function($task) {
    //测试workerman,1秒钟写一次日志
    $time_interval = 1;
    Timer::add($time_interval, function(){
        //环球   当客户三天未跟进标记失效。
        $CustomerInfo=Db::name('yonghui_customer')->where(['sourceId'=>['in','3,4'],'followStatus'=>1])->field('id,createTime,followStatus,sourceId')->select()->toArray();
        foreach ($CustomerInfo as $k=>$v){
            $followinfo=Db::name('yonghui_follow')->where(['customerId'=>$v['id']])->limit(1)->order('createTime desc')->field('customerId,createTime')->find();
            if($followinfo){
                if((time()-$followinfo['createTime'])>259200){
                    $log = WsgtLog::instance();
                    $log->setFilename('thirdUpdate/updateInfo');
                    $log->info('客户id:'.$v['id'], '修改的客户id');
                    Db::name('yonghui_customer')->where(['id'=>$v['id']])->update(['followStatus'=>2,'timeouttype'=>2]);
                }
            }else{
                //判断客户添加时间
                if((time()-$v['createTime'])>259200){
                    $log = WsgtLog::instance();
                    $log->setFilename('thirdUpdate/updateInfo');
                    $log->info('客户id:'.$v['id'], '修改的客户id');
                    Db::name('yonghui_customer')->where(['id'=>$v['id']])->update(['followStatus'=>2,'timeouttype'=>2]);
                }
            }
        }
    });
};
//运行worker
Worker::runAll();